/**
 *
 * @description:
 * @author: junyong.hong
 * @createTime: 2019/3/13
 * @version: 1.0.0.0
 * @history:
 *    1、
 *    2、
 *
 */
const mongoose = require('mongoose')
const Comment = mongoose.model('Comment')

exports.save = async (ctx, next) => {
    const commentData = ctx.request.body.comment

    console.log('commentData', commentData)

    // 某一个人对另一个人进行回复
    if (commentData.cid) {  // cid某一条评论的id
        let comment = await Comment.findOne({
            _id: commentData.cid
        })

        const reply = {
            from: commentData.from,
            to: commentData.tid,
            content: commentData.content
        }

        comment.replies.push(reply)

        await comment.save()

        ctx.body = { success: true }

    } else { // 对这部电影进行回复
        let comment = new Comment({
            // 对哪部电影进行评论
            movie: commentData.movie,
            // 来自于谁
            from: commentData.from,
            // 具体的内容
            content: commentData.content
        })

        await comment.save()

        ctx.body = { success: true }
    }
}










